package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.UserGoWuChe;
import com.example.mapper.UserGouWUCheMapper;
import com.example.service.UserGouWuCheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/gouwu")
public class UserGouWuCheController {

    @Resource
    private UserGouWuCheService userGouWuCheService;
    @Autowired
    private UserGouWUCheMapper userGouWUCheMapper;

    /*  根据id删除*/
    @GetMapping("deletes{id}")
    public Boolean delete(Long id) {
        System.out.println(id);
        return userGouWuCheService.removeById(id);
    }

    /*根据id查询*/
    @GetMapping("get{id}")
    public UserGoWuChe ge(Long id) {
        QueryWrapper<UserGoWuChe> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        return userGouWUCheMapper.selectById(id);
    }

    @PostMapping("/add")
    public Boolean add(@RequestBody UserGoWuChe userGoWuChe) {
        return userGouWuCheService.save(userGoWuChe);
    }


    @PostMapping("/update")
    public Boolean update(@RequestBody UserGoWuChe userGoWuChe) {
        return userGouWuCheService.updateById(userGoWuChe);
    }


    @GetMapping("/list")
    public List<UserGoWuChe> list() {
        return userGouWuCheService.list();
    }


    /**
     * 分页查询
     */
    @GetMapping("/page")
    public List<UserGoWuChe> page(int a, int b) {
        Page<UserGoWuChe> employees = userGouWUCheMapper.selectPage(new Page<>(a, b), null);
        List list = new ArrayList<>();
        list.add(employees.getRecords());
        list.add(employees.getTotal());
        return list;
    }

    /**
     * 条件查询 id
     */

    @RequestMapping("/like")
    public Object selectList(UserGoWuChe id) {
        List<UserGoWuChe> list = userGouWuCheService.selectList(id);
        return list;
    }
}
